﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.cms.businesslogic.web;
using umbraco.BasePages;

namespace TheOutfield.UmbExt.DocTypeExtensions.Handlers
{
    /// <summary>
    /// Summary description for OpenAssociatedDocType
    /// </summary>
    public class OpenAssociatedDocType : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            Document doc = new Document(NodeId);
            context.Response.Redirect(string.Format("/umbraco/settings/editNodeTypeNew.aspx?id={0}", doc.ContentType.Id));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private int NodeId
        {
            get
            {
                int result = 0;
                int.TryParse(HttpContext.Current.Request.QueryString["nodeid"], out result);
                return result;
            }
        }
    }
}